import request from '@/utils/request'

/**
 * 新建
 * @param {*} data
 * @returns
 */
export const add = (data, url) => {
  console.log('add')
  return request({
    url: `/${url}`,
    method: 'POST',
    data
  })
}

/**
 * 查询数据
 * return promise
 */
export const list = (searchPage, url) => {
  return request({
    url: `/${url}/page`,
    method: 'POST',
    data: searchPage
  })
}

/**
 * 修改
 * @param {*} job
 * @returns
 */
export const modify = (data, id, url) => {
  return request({
    url: `/${url}/${id}`,
    method: 'PUT',
    data
  })
}

/**
 * 删除
 * @param {*} ids
 */
export const deleteByIds = (ids, url) => {
  return request.delete(`/${url}`, ids)
}

/**
 * 删除
 * @param {*} id
 * @returns
 */
export const deleteById = (id, url) => {
  return request.delete(`/${url}/${id}`)
}

/**
 * 使用单引号需要拼接 使用 ` 可以赋值
 * @param {*} id
 * @returns
 */
export const getById = (id, url) => {
  return request({
    url: `/${url}/${id}`,
    method: 'GET'
  })
}

export const downLoadFile = fileName => {
  return request({
    url: `/file/auth/${fileName}`,
    method: 'GET'
  })
}

/**
 * @param {*} searchPage
 * @returns
 */
export const exportData = (searchPage, url) => {
  return request({
    url: `/${url}/exportData`,
    method: 'POST',
    data: searchPage,
    responseType: 'blob'
  })
}

/**
 * 下载文件
 * @param {*} uuid
 * @returns
 */
export const exportFile = uuid => {
  return request({
    url: `/file/${uuid}`,
    method: 'GET',
    responseType: 'blob'
  })
}

/**
 * 根据uuid获取文件相关信息
 * @param {*} uuid
 * @returns
 */
export const getFileMessage = uuid => {
  return request({
    url: `/file/self/${uuid}`,
    method: 'GET'
  })
}
